package com.google.zxing.multi.qrcode;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.DecodeHintType;
import com.google.zxing.NotFoundException;
import com.google.zxing.ReaderException;
import com.google.zxing.Result;
import com.google.zxing.ResultMetadataType;
import com.google.zxing.ResultPoint;
import com.google.zxing.common.DecoderResult;
import com.google.zxing.common.DetectorResult;
import com.google.zxing.multi.MultipleBarcodeReader;
import com.google.zxing.multi.qrcode.detector.MultiDetector;
import com.google.zxing.qrcode.QRCodeReader;
import com.google.zxing.qrcode.decoder.Decoder;
import com.google.zxing.qrcode.decoder.QRCodeDecoderMetaData;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public final class QRCodeMultiReader extends QRCodeReader
  implements MultipleBarcodeReader
{
  private static final Result[] EMPTY_RESULT_ARRAY = new Result[0];
  private static final ResultPoint[] NO_POINTS = new ResultPoint[0];

  private static List<Result> processStructuredAppend(List<Result> paramList)
  {
    Iterator localIterator1 = paramList.iterator();
    do
    {
      boolean bool = localIterator1.hasNext();
      i = 0;
      if (!bool)
        break;
    }
    while (!((Result)localIterator1.next()).getResultMetadata().containsKey(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE));
    int i = 1;
    if (i == 0)
      return paramList;
    ArrayList localArrayList1 = new ArrayList();
    ArrayList localArrayList2 = new ArrayList();
    Iterator localIterator2 = paramList.iterator();
    while (localIterator2.hasNext())
    {
      Result localResult4 = (Result)localIterator2.next();
      localArrayList1.add(localResult4);
      if (localResult4.getResultMetadata().containsKey(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE))
        localArrayList2.add(localResult4);
    }
    Collections.sort(localArrayList2, new SAComparator(null));
    StringBuilder localStringBuilder = new StringBuilder();
    int j = 0;
    int k = 0;
    Iterator localIterator3 = localArrayList2.iterator();
    while (localIterator3.hasNext())
    {
      Result localResult3 = (Result)localIterator3.next();
      localStringBuilder.append(localResult3.getText());
      j += localResult3.getRawBytes().length;
      if (localResult3.getResultMetadata().containsKey(ResultMetadataType.BYTE_SEGMENTS))
      {
        Iterator localIterator6 = ((Iterable)localResult3.getResultMetadata().get(ResultMetadataType.BYTE_SEGMENTS)).iterator();
        while (localIterator6.hasNext())
          k += ((byte[])localIterator6.next()).length;
      }
    }
    byte[] arrayOfByte1 = new byte[j];
    byte[] arrayOfByte2 = new byte[k];
    int m = 0;
    int n = 0;
    Iterator localIterator4 = localArrayList2.iterator();
    while (localIterator4.hasNext())
    {
      Result localResult2 = (Result)localIterator4.next();
      System.arraycopy(localResult2.getRawBytes(), 0, arrayOfByte1, m, localResult2.getRawBytes().length);
      m += localResult2.getRawBytes().length;
      if (localResult2.getResultMetadata().containsKey(ResultMetadataType.BYTE_SEGMENTS))
      {
        Iterator localIterator5 = ((Iterable)localResult2.getResultMetadata().get(ResultMetadataType.BYTE_SEGMENTS)).iterator();
        while (localIterator5.hasNext())
        {
          byte[] arrayOfByte3 = (byte[])localIterator5.next();
          System.arraycopy(arrayOfByte3, 0, arrayOfByte2, n, arrayOfByte3.length);
          n += arrayOfByte3.length;
        }
      }
    }
    Result localResult1 = new Result(localStringBuilder.toString(), arrayOfByte1, NO_POINTS, BarcodeFormat.QR_CODE);
    if (k > 0)
    {
      ArrayList localArrayList3 = new ArrayList();
      localArrayList3.add(arrayOfByte2);
      localResult1.putMetadata(ResultMetadataType.BYTE_SEGMENTS, localArrayList3);
    }
    localArrayList1.add(localResult1);
    return localArrayList1;
  }

  public Result[] decodeMultiple(BinaryBitmap paramBinaryBitmap)
    throws NotFoundException
  {
    return decodeMultiple(paramBinaryBitmap, null);
  }

  public Result[] decodeMultiple(BinaryBitmap paramBinaryBitmap, Map<DecodeHintType, ?> paramMap)
    throws NotFoundException
  {
    ArrayList localArrayList = new ArrayList();
    DetectorResult[] arrayOfDetectorResult = new MultiDetector(paramBinaryBitmap.getBlackMatrix()).detectMulti(paramMap);
    int i = arrayOfDetectorResult.length;
    int j = 0;
    while (true)
    {
      DetectorResult localDetectorResult;
      if (j < i)
        localDetectorResult = arrayOfDetectorResult[j];
      try
      {
        DecoderResult localDecoderResult = getDecoder().decode(localDetectorResult.getBits(), paramMap);
        ResultPoint[] arrayOfResultPoint = localDetectorResult.getPoints();
        if ((localDecoderResult.getOther() instanceof QRCodeDecoderMetaData))
          ((QRCodeDecoderMetaData)localDecoderResult.getOther()).applyMirroredCorrection(arrayOfResultPoint);
        Result localResult = new Result(localDecoderResult.getText(), localDecoderResult.getRawBytes(), arrayOfResultPoint, BarcodeFormat.QR_CODE);
        List localList2 = localDecoderResult.getByteSegments();
        if (localList2 != null)
          localResult.putMetadata(ResultMetadataType.BYTE_SEGMENTS, localList2);
        String str = localDecoderResult.getECLevel();
        if (str != null)
          localResult.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, str);
        if (localDecoderResult.hasStructuredAppend())
        {
          localResult.putMetadata(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE, Integer.valueOf(localDecoderResult.getStructuredAppendSequenceNumber()));
          localResult.putMetadata(ResultMetadataType.STRUCTURED_APPEND_PARITY, Integer.valueOf(localDecoderResult.getStructuredAppendParity()));
        }
        localArrayList.add(localResult);
        label210: j++;
        continue;
        if (localArrayList.isEmpty())
          return EMPTY_RESULT_ARRAY;
        List localList1 = processStructuredAppend(localArrayList);
        return (Result[])localList1.toArray(new Result[localList1.size()]);
      }
      catch (ReaderException localReaderException)
      {
        break label210;
      }
    }
  }

  private static final class SAComparator
    implements Comparator<Result>, Serializable
  {
    public int compare(Result paramResult1, Result paramResult2)
    {
      int i = ((Integer)paramResult1.getResultMetadata().get(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE)).intValue();
      int j = ((Integer)paramResult2.getResultMetadata().get(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE)).intValue();
      if (i < j)
        return -1;
      if (i > j)
        return 1;
      return 0;
    }
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.google.zxing.multi.qrcode.QRCodeMultiReader
 * JD-Core Version:    0.6.2
 */